package com.qtenv.datasync.service.controller;


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.map.MapUtil;
import com.qtenv.datasync.base.Result;
import com.qtenv.datasync.service.entity.Tag;
import com.qtenv.datasync.service.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 分区参数标签页 前端控制器
 * </p>
 *
 * @author CBL
 * @since 2022-08-01
 */
@RestController
@RequestMapping("/tag")
public class TagController {
    @Autowired
    private TagService tagService;

    @GetMapping("/getZoneStatusPartition")
    public Result<?> getZoneStatusPartition(@RequestParam("tenantId") String tenantId,
                                            @RequestParam("levelType") String levelType) {
        return Result.ok(this.transformZoneStatusPartition(tagService.getZoneStatusPartition(tenantId, levelType)));
    }

    private List<Map<String, Object>> transformZoneStatusPartition(Tag tag) {
        List<Map<String, Object>> result = CollectionUtil.newArrayList();

        if (tag != null) {
            Map<String, Object> mapGh = MapUtil.newHashMap();
            mapGh.put("name", "规划");
            mapGh.put("value", tag.getGh());
            result.add(mapGh);

            Map<String, Object> mapSj = MapUtil.newHashMap();
            mapSj.put("name", "设计");
            mapSj.put("value", tag.getSj());
            result.add(mapSj);

            Map<String, Object> mapWc = MapUtil.newHashMap();
            mapWc.put("name", "完成");
            mapWc.put("value", tag.getWc());
            result.add(mapWc);
        }

        return result;
    }
}
